//返回省份以及代码
import list from './pc-code.json'
export const getProvinceList = () => {
    //返回省份列表
    return list.map(item => {
        return {
            code: item.code + '0000',
            name: item.name,
            // children: item.children
            // children中的code是市级的code，不足6位的补0
            children: item.children.map(item2 => {
                return {
                    code: (item2.code).toString().padEnd(6, '0'),
                    name: item2.name
                }
            })
        }
    })
}



//根据省份code获取省份名称
export const getProvinceNameByCode = (code) => {
    let province = list.find(item => {
        return (item.code + '0000') == code
    })
    return province ? province.name : ''
}

//根据市级code获取市级名称
export const getCityNameByCode = (code) => {
    //市级code为6位，前两位是省份code
    let provinceCode = (code + '').substring(0, 2)
    let province = list.find(item => {
        return item.code == provinceCode
    })
    console.log(province);
    if (province) {
        let city = province.children.find(item => {
            return (item.code).toString().padEnd(6, '0') == code
        })
        return city ? city.name : ''
    }
}